package book;

public class InterruptTest2 {

	static class MyThread extends Thread{
		
		public void run(){
			
			try {
				for(int i = 0; i < 500000 * 100; i++){
					
					if(isInterrupted()){
						
						System.out.println("线程被中断");
						throw new InterruptedException();
					}
					System.out.println("i=" + i);
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) throws InterruptedException {
		
		MyThread t = new MyThread();
		t.start();
		
		//启动0.3秒后中断线程
		Thread.sleep(300);
		t.interrupt();
	}
}
